package aip.ui.user.srvc;

import java.util.Map;

import org.springframework.util.Assert;

import aip.core.dao.user.UserDao;
import aip.core.model.user.User;

public class AuthenticationService
{
    private String loginUrl;
    private String logoutUrl;
    private String faildUrl;
    private String successUrl;
    private String userLoginUrl;
    private Map<String, Boolean> filterUrl;
    private Map<String, Boolean> adminUrl;
    private Map<String, Boolean> expertUrl;
    private Map<String, Boolean> companyUrl;
    private Map<String, Boolean> serviceUrl;

    private UserDao userDao;

    public User getValidUser(String username, String password)
    {
        Assert.hasText(username);
        Assert.hasText(password);
        User user = this.userDao.getValidUser(username);
        if (user != null
                && userDao.encodePassword(password).equals(user.getPassword()))
        {
            return user;
        }
        return null;
    }

    /**
     * @param userDao
     *        the userDao to set
     */
    public void setUserDao(UserDao userDao)
    {
        this.userDao = userDao;
    }

    /**
     * @param loginUrl
     *        the loginUrl to set
     */
    public void setLoginUrl(String loginUrl)
    {
        this.loginUrl = loginUrl;
    }

    /**
     * @param logoutUrl
     *        the logoutUrl to set
     */
    public void setLogoutUrl(String logoutUrl)
    {
        this.logoutUrl = logoutUrl;
    }

    /**
     * @param faildUrl
     *        the faildUrl to set
     */
    public void setFaildUrl(String errorUrl)
    {
        this.faildUrl = errorUrl;
    }

    /**
     * @return the loginUrl
     */
    public String getLoginUrl()
    {
        return loginUrl;
    }

    /**
     * @return the logoutUrl
     */
    public String getLogoutUrl()
    {
        return logoutUrl;
    }

    /**
     * @return the faildUrl
     */
    public String getFaildUrl()
    {
        return faildUrl;
    }

    /**
     * @return the successUrl
     */
    public String getSuccessUrl()
    {
        return successUrl;
    }

    /**
     * @param successUrl
     *        the successUrl to set
     */
    public void setSuccessUrl(String successUrl)
    {
        this.successUrl = successUrl;
    }

    /**
     * @return the userDao
     */
    public UserDao getUserDao()
    {
        return userDao;
    }

    /**
     * @return the filterUrl
     */
    public Map<String, Boolean> getFilterUrl()
    {
        return filterUrl;
    }

    /**
     * @param filterUrl
     *        the filterUrl to set
     */
    public void setFilterUrl(Map<String, Boolean> filterUrl)
    {
        this.filterUrl = filterUrl;
    }

    /**
     * @return the adminUrl
     */
    public Map<String, Boolean> getAdminUrl()
    {
        return adminUrl;
    }

    /**
     * @param adminUrl
     *        the adminUrl to set
     */
    public void setAdminUrl(Map<String, Boolean> adminUrl)
    {
        this.adminUrl = adminUrl;
    }

    /**
     * @return the expertUrl
     */
    public Map<String, Boolean> getExpertUrl()
    {
        return expertUrl;
    }

    /**
     * @param expertUrl
     *        the expertUrl to set
     */
    public void setExpertUrl(Map<String, Boolean> expertUrl)
    {
        this.expertUrl = expertUrl;
    }

    /**
     * @return the companyUrl
     */
    public Map<String, Boolean> getCompanyUrl()
    {
        return companyUrl;
    }

    /**
     * @param companyUrl
     *        the companyUrl to set
     */
    public void setCompanyUrl(Map<String, Boolean> companyUrl)
    {
        this.companyUrl = companyUrl;
    }

    /**
     * @return the serviceUrl
     */
    public Map<String, Boolean> getServiceUrl()
    {
        return serviceUrl;
    }

    /**
     * @param serviceUrl
     *        the serviceUrl to set
     */
    public void setServiceUrl(Map<String, Boolean> serviceUrl)
    {
        this.serviceUrl = serviceUrl;
    }

    /**
     * @return the userLoginUrl
     */
    public String getUserLoginUrl()
    {
        return userLoginUrl;
    }

    /**
     * @param userLoginUrl
     *        the userLoginUrl to set
     */
    public void setUserLoginUrl(String userLoginUrl)
    {
        this.userLoginUrl = userLoginUrl;
    }
}
